public abstract class SortedTree extends StringTree {
	
	public abstract String traverse();
	
	public SortedTree(String node) {
		super(node);
	}
	
	public SortedTree() {
		super();
	}
	
	@Override
	public String search(String node) {
		return recSearch(node, rootNode);
	}
	
	@Override
	public void add(String node) {
		if (this.rootNode != null) {
			recAdd(node, rootNode);
		} else {
			this.rootNode = new StringNode(node);
		}
	}
	
	private void recAdd(String newNode, StringNode currentNode) {
		if (newNode.compareTo(currentNode.getLabel()) < 0) {
			if (currentNode.getLeftChild() == null) {
				currentNode.setLeftChild(new StringNode(newNode));
			} else {
				recAdd(newNode, currentNode.getLeftChild());
			}
		} else {
			if (currentNode.getRightChild() == null) {
				currentNode.setRightChild(new StringNode(newNode));
			} else {
				recAdd(newNode, currentNode.getRightChild());
			}
		}
	}
	
	private String recSearch(String node, StringNode currentNode) {
		String temp = "";
		if (currentNode == null) {
			return "Knoten wurde nicht gefunden";
		} else {
			if (node.equals(currentNode.getLabel())) {
				return temp;
			}
			if (node.compareTo(currentNode.getLabel()) < 0) {
				System.out.println("suche links von " + currentNode.getLabel());
				temp = recSearch(node, currentNode.getLeftChild());
				if (temp.equals("Knoten wurde nicht gefunden")) {
					return temp;
				} else {
					return "left " + temp;
				}
			} else {
				System.out.println("suche rechts von " + currentNode.getLabel());
				temp = recSearch(node, currentNode.getRightChild());
				if (temp.equals("Knoten wurde nicht gefunden")) {
					return temp;
				} else {
					return "right " + temp;
				}
			}
		}
	}
}
